If the src positions for gradients are nonsensical, don't render anything,
authorMatthias Clasen <mclasen@redhat.com>
Tue, 17 Jan 2006 20:02:54 +0000 (20:02 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 17 Jan 2006 20:02:54 +0000 (20:02 +0000)
2006-01-17  Matthias Clasen  <mclasen@redhat.com>

* pixbuf-render.c: If the src positions for gradients
are nonsensical, don't render anything, rather than
read out of bounds.

modules/engines/pixbuf/ChangeLog
modules/engines/pixbuf/pixbuf-render.c

index 77b47f4befaefac3687034ec41f2cc5b7d50da9c..68f29c810ef7351b0bc92da14c0b3c9627f0b0cd 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-17  Matthias Clasen  <mclasen@redhat.com>
+
+       * pixbuf-render.c: If the src positions for gradients
+       are nonsensical, don't render anything, rather than 
+       read out of bounds.  
+       
 2006-01-16  Matthias Clasen  <mclasen@redhat.com>
 
        * pixbuf-draw.c:
index 4d965a057c513b2ffde5242829ce98baf7d828c1..916bbd87ca19bab6081690e7efeecf1e220eaeaa 100644 (file)
@@ -43,6 +43,12 @@ bilinear_gradient (GdkPixbuf    *src,
   GdkPixbuf *result;
   int i, j, k;
 
+  if (src_x == 0 || src_y == 0)
+    {
+      g_warning ("invalid source position for bilinear gradient\n");
+      return NULL;
+    }
+
   p1 = src_pixels + (src_y - 1) * src_rowstride + (src_x - 1) * n_channels;
   p2 = p1 + n_channels;
   p3 = src_pixels + src_y * src_rowstride + (src_x - 1) * n_channels;
@@ -96,6 +102,12 @@ horizontal_gradient (GdkPixbuf    *src,
   GdkPixbuf *result;
   int i, j, k;
 
+  if (src_x == 0)
+    {
+      g_warning ("invalid source position for horizontal gradient\n");
+      return NULL;
+    }
+
   result = gdk_pixbuf_new (GDK_COLORSPACE_RGB, n_channels == 4, 8,
                           width, height);
   dest_rowstride = gdk_pixbuf_get_rowstride (result);
@@ -145,6 +157,12 @@ vertical_gradient (GdkPixbuf    *src,
   GdkPixbuf *result;
   int i, j;
 
+  if (src_y == 0)
+    {
+      g_warning ("invalid source position for vertical gradient\n");
+      return NULL;
+    }
+
   top_pixels = src_pixels + (src_y - 1) * src_rowstride + (src_x) * n_channels;
   bottom_pixels = top_pixels + src_rowstride;
 
@@ -304,7 +322,7 @@ pixbuf_render (GdkPixbuf    *src,
               gint          dest_width,
               gint          dest_height)
 {
-  GdkPixbuf *tmp_pixbuf;
+  GdkPixbuf *tmp_pixbuf = NULL;
   GdkRectangle rect;
   int x_offset, y_offset;
   gboolean has_alpha = gdk_pixbuf_get_has_alpha (src);
@@ -382,7 +400,7 @@ pixbuf_render (GdkPixbuf    *src,
       x_offset = rect.x - dest_x;
       y_offset = rect.y - dest_y;
     }
-  else 
+  else if (src_width > 0 && src_height > 0)
     {
       double x_scale = (double)dest_width / src_width;
       double y_scale = (double)dest_height / src_height;
@@ -415,22 +433,25 @@ pixbuf_render (GdkPixbuf    *src,
       y_offset = 0;
     }
 
-  if (mask)
+  if (tmp_pixbuf)
     {
-      gdk_pixbuf_render_threshold_alpha (tmp_pixbuf, mask,
-                                        x_offset, y_offset,
-                                        rect.x, rect.y,
-                                        rect.width, rect.height,
-                                        128);
+      if (mask)
+       {
+         gdk_pixbuf_render_threshold_alpha (tmp_pixbuf, mask,
+                                            x_offset, y_offset,
+                                            rect.x, rect.y,
+                                            rect.width, rect.height,
+                                            128);
+       }
+      
+      gdk_draw_pixbuf (window, NULL, tmp_pixbuf,
+                      x_offset, y_offset,
+                      rect.x, rect.y,
+                      rect.width, rect.height,
+                      GDK_RGB_DITHER_NORMAL,
+                      0, 0);
+      g_object_unref (tmp_pixbuf);
     }
-
-  gdk_draw_pixbuf (window, NULL, tmp_pixbuf,
-                  x_offset, y_offset,
-                  rect.x, rect.y,
-                  rect.width, rect.height,
-                  GDK_RGB_DITHER_NORMAL,
-                  0, 0);
-  g_object_unref (tmp_pixbuf);
 }
 
 ThemePixbuf *